package rsj.sql.exportlog;

import com.rlyy.aibase.utils.base.Node;
import com.rlyy.aibase.utils.base.TableNode;
import rsj.annotation.Param;
import rsj.annotation.Select;
import rsj.annotation.Update;
import rsj.api.report.entity.ReportExportLog;

/**
 * 导出日志
 *
 * @author yuanqinglong
 * @since 2021/7/15 15:43
 */
public interface ExportLogDao {


    /**
     * 保存日志
     *
     * @param exportLog 导出日志
     */
    @Update("INSERT INTO sys.export_log (log_id,export_file_id,export_file_name,file_create_status,file_create_tm,export_tm,export_operson)" +
            " VALUES ( #{logId} , #{exportFileId}, #{exportFileName} ,#{fileCreateStatus} ,#{fileCreateTm},#{exportTm},#{exportOperson})")
    void saveExportLog(ReportExportLog exportLog);


    /**
     * 导出日志更新状态
     *
     * @param exportLog 导出日志
     */
    @Update("UPDATE sys.export_log SET file_create_status = #{fileCreateStatus},export_file_id = #{exportFileId} WHERE log_id = #{logId}")
    void updateExportLogStatus(ReportExportLog exportLog);


    /**
     * 我的导出列表
     *
     * @param userId     用户id
     * @param pageSize   页面大小
     * @param pageOffset offset
     * @return {@link TableNode}
     */
    @Select("SELECT log_id, export_file_id, export_file_name, file_create_status, file_create_tm, export_tm " +
            "FROM sys.export_log WHERE export_operson = #{userId}  ORDER BY export_tm DESC OFFSET #{pageOffset} LIMIT #{pageSize}")
    TableNode myExportList(@Param(value = "userId") String userId,@Param(value = "pageSize") Integer pageSize,@Param(value = "pageOffset") Integer pageOffset);


    /**
     * 我的导出数
     *
     * @param userId 用户id
     * @return {@link Node}
     */
    @Select("SELECT COUNT(*) FROM sys.export_log WHERE export_operson = #{userId}")
    Node myExportCount(@Param(value = "userId") String userId);

}
